home *** CD-ROM | disk | FTP | other *** search
/ Champak 145 / (Vol 145) Dec 21 2011.iso / Games / hearts.swf / scripts / DefineSprite_638 / frame_1 / DoAction_10.as next >
Encoding:
Text File  |  2011-12-21  |  2.6 KB  |  122 lines

  1. this.maxFlyS = 1.5;
  2. this.maxFlyR = 100;
  3. this.flyA = new Array();
  4. this.createFly = function()
  5. {
  6.    var t = this;
  7.    t.attachMovie("fly","f" + t.fd,t.fd);
  8.    var n = t["f" + t.fd];
  9.    n.rad = 30;
  10.    n.ang = random(360);
  11.    n.arriveAng = false;
  12.    n.angDS = 0;
  13.    n.angS = 0;
  14.    var side = random(4);
  15.    if(side == 0)
  16.    {
  17.       n.cx = random(t.stageW);
  18.       n.cy = (- n._height) / 2 - 30;
  19.    }
  20.    else if(side == 1)
  21.    {
  22.       n.cx = 600 + n._width / 2 + 30;
  23.       n.cy = random(t.stageH);
  24.    }
  25.    else if(side == 2)
  26.    {
  27.       n.cx = random(t.stageW);
  28.       n.cy = t.stageH + 15 + n._height / 2 + 30;
  29.    }
  30.    else if(side == 3)
  31.    {
  32.       n.cx = (- n._width) / 2 - 30;
  33.       n.cy = random(t.stageH);
  34.    }
  35.    n._x = n.cx + n.rad * Math.cos(n.ang * t.rc);
  36.    n._y = n.cy + n.rad * Math.sin(n.ang * t.rc);
  37.    n.mx = Math.random() * 1 + 0.1;
  38.    n.my = Math.random() * 1 + 0.1;
  39.    t.flyA.push(n);
  40.    t.addD("f");
  41. };
  42. this.moveFly = function()
  43. {
  44.    var t = this;
  45.    var i = t.flyA.length - 1;
  46.    while(i >= 0)
  47.    {
  48.       var n = t.flyA[i];
  49.       n.cx += n.mx;
  50.       n.cy += n.my;
  51.       n.mx += Math.random() * 0.3 - 0.15;
  52.       n.my += Math.random() * 0.3 - 0.15;
  53.       if(n.mx > t.maxFlyS)
  54.       {
  55.          n.mx = t.maxFlyS;
  56.       }
  57.       else if(n.mx < - t.maxFlyS)
  58.       {
  59.          n.mx = - t.maxFlyS;
  60.       }
  61.       if(n.my > t.maxFlyS)
  62.       {
  63.          n.my = t.maxFlyS;
  64.       }
  65.       else if(n.my < - t.maxFlyS)
  66.       {
  67.          n.my = - t.maxFlyS;
  68.       }
  69.       if(n._x < t.startX)
  70.       {
  71.          n.mx += 0.05;
  72.       }
  73.       else if(n._x > t.stageW)
  74.       {
  75.          n.mx -= 0.05;
  76.       }
  77.       if(n._y < 0)
  78.       {
  79.          n.my += 0.05;
  80.       }
  81.       else if(n._y > t.stageH)
  82.       {
  83.          n.my -= 0.05;
  84.       }
  85.       n.rad += Math.random() * 2 - 1;
  86.       if(n.rad > t.maxFlyR)
  87.       {
  88.          n.rad = t.maxFlyR;
  89.       }
  90.       else if(n.rad < 0)
  91.       {
  92.          n.rad = 0;
  93.       }
  94.       if(Math.abs(n.angS) < 1)
  95.       {
  96.          var dir = random(2);
  97.          if(dir == 0)
  98.          {
  99.             dir = -1;
  100.          }
  101.          n.angDS = (random(10) + 3) * dir;
  102.          n.arriveAng = false;
  103.       }
  104.       if(n.arriveAng == false and Math.abs(n.angDS - n.angS) > 1)
  105.       {
  106.          n.angS += (n.angDS - n.angS) / 10;
  107.          if(Math.abs(n.angDS - n.angS) <= 1)
  108.          {
  109.             n.arriveAng = true;
  110.          }
  111.       }
  112.       else
  113.       {
  114.          n.angS *= 0.9;
  115.       }
  116.       n.ang += n.angS;
  117.       n._x = n.cx + n.rad * Math.cos(n.ang * t.rc);
  118.       n._y = n.cy + n.rad * Math.sin(n.ang * t.rc);
  119.       i--;
  120.    }
  121. };
  122.